<template>
  <div class="choose">
    <el-select v-model="value" placeholder="请选择">
      <el-option
        v-for="item in employee"
        :key="item.employee_id"
        :label="item.employee_name"
        :value="item.employee_id"
      >
      </el-option>
    </el-select>
    <el-button type="primary" @click="moveToOtherEmp">转移</el-button>
    <el-button type="info" @click="moveToTrash">
      <i class="el-icon-delete"></i> 批量删除</el-button
    >
    <el-button type="primary" @click="moveToCustomerPoll"
      ><i class="el-icon-position"></i> 转入公海</el-button
    >
    <el-button type="info" @click="modifyCustomerProtectedSetting"
      ><i class="el-icon-setting"></i> 保护期例外设置</el-button
    >
  </div>
</template>

<script>
import {
  moveToOtherEmpAxios,
  moveToTrashAxios,
  moveToCustomerPollAxios,
  modifyCustomerProtectedSettingAxios,
} from "../http/apis/userManageApi";
export default {
  props: {
    checkVal: Array,
    employee: Array,
  },
  data() {
    return {
      value: "",
      statusval: 0,
    };
  },
  methods: {
    //转移客户给指定业务员
    moveToOtherEmp() {
      moveToOtherEmpAxios({
        customerIds: this.checkVal,
        employeeId: this.value,
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "转移成功",
          });
          this.$emit("aa");
        })
        .catch(() => {
          this.$message({
            type: "error",
            message: "转移失败",
          });
        });
    },
    moveToTrash() {
      if (this.checkVal.length <= 0) {
        this.$alert("您没有选择任何客户", "信息")
          .then(() => {})
          .catch(() => {});
      } else {
        moveToTrashAxios({
          customerIds: this.checkVal,
          delInfo: [1],
          remark: "批量删除",
        })
          .then(() => {
            this.$message({
              type: "success",
              message: "批量删除成功",
            });
            this.$emit("aa");
          })
          .catch(() => {
            this.$message({
              type: "error",
              message: "批量删除失败",
            });
          });
      }
    },
    moveToCustomerPoll() {
      moveToCustomerPollAxios(this.checkVal)
        .then(() => {
          this.$message({
            type: "success",
            message: "转移到公海成功",
          });
          this.$emit("aa");
        })
        .catch(() => {
          this.$message({
            type: "error",
            message: "转移到公海失败",
          });
        });
    },
    modifyCustomerProtectedSetting() {
      if (this.checkVal.length > 0) {
        this.$alert(
          `<div>
            <h2>提示操作</h2>
            <div class="box">
              <label class="radio" ><input type="radio" name="status" value="0" class="check" checked>不参与保护期</label>
              <label class="radio" ><input type="radio" name="status" value="1" class="check">参与保护期</label>
            </div>
            <div>已选中客户编号:${this.checkVal}</div>
          </div>`,
          "保护期例外设置:",
          {
            dangerouslyUseHTMLString: true,
          }
        )
          .then(() => {
            //获取check值
            let status1 = document.getElementsByClassName("check");
            for (let a = 0; a < status1.length; a++) {
              if (status1[a].checked) {
                this.statusval = status1[a].value;
              }
            }
            //发起请求
            modifyCustomerProtectedSettingAxios({
              checkVal: this.checkVal,
              statusval: parseInt(this.statusval),
            })
              .then(() => {
                this.$message({
                  type: "success",
                  message: "修改成功",
                });
                this.$emit("aa");
              })
              .catch(() => {
                this.$message({
                  type: "error",
                  message: "修改失败",
                });
              });
          })
          .catch(() => {
            //取消后执行
            this.$message("取消设置");
          });
      } else {
        this.$alert("您没有选择任何客户", "信息")
          .then(() => {})
          .catch(() => {});
      }
      // modifyCustomerProtectedSettingAxios();
    },
  },
};
</script>

<style lang="scss" scoped>
.el-select {
  width: 100px;
}
h3 {
  text-align: center;
}
</style>